package com.jiawa.train.member.controller;

import com.jiawa.train.common.resp.Result;
import com.jiawa.train.member.req.MemberLoginReq;
import com.jiawa.train.member.req.MemberSendCodeReq;
import com.jiawa.train.member.resp.MemberLoginResp;
import com.jiawa.train.member.service.MemberService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/member")
public class MemberController {
    @Resource
    private MemberService memberService;


    @PostMapping("/sendCode")
    public Result sendCode(@Valid @RequestBody MemberSendCodeReq req){
        String code = memberService.sendCode(req);
        return Result.success(code);
    }

    @PostMapping("/login")
    public Result<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq req){
        MemberLoginResp memberLoginResp = memberService.login(req);
        return Result.success(memberLoginResp);
    }

}
